import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_mvvm_lite/app/routes/app_routes.dart';
import 'package:getx_mvvm_lite/core/state/page_state.dart';
import 'package:getx_mvvm_lite/features/counter/counter_view_model.dart';
import 'package:getx_mvvm_lite/shared/widgets/app_button.dart';
import 'package:getx_mvvm_lite/shared/widgets/state_scaffold.dart';

class CounterPage extends StatelessWidget {
  const CounterPage({super.key});

  @override
  Widget build(BuildContext context) {
    final vm = Get.put(CounterViewModel());
    vm.setContent();

    return Obx(() => StateScaffold(
          state: vm.pageState.value,
          title: 'Counter',
          child: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Count: ${vm.count.value}', style: Theme.of(context).textTheme.headlineSmall),
                const SizedBox(height: 16),
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    AppButton(text: '+', onPressed: vm.increment),
                    const SizedBox(width: 12),
                    AppButton(text: '-', onPressed: vm.decrement),
                  ],
                ),
                const SizedBox(height: 24),
                AppButton(text: 'Go to Todo', onPressed: () => Get.toNamed(Routes.todo)),
              ],
            ),
          ),
        ));
  }
}